package com.library.weidget;

import com.jtjrenren.android.taxi.passenger.R;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class CustomFiveStars extends LinearLayout {
	private ImageView iv_1;
	private ImageView iv_2;
	private ImageView iv_3;
	private ImageView iv_4;
	private ImageView iv_5;

	public CustomFiveStars(Context context) {
		super(context);
		initView();
	}

	public CustomFiveStars(Context context, AttributeSet attrs) {
		super(context, attrs);
		initView();
	}

	private void initView() {
		View.inflate(getContext(), R.layout.custome_fivestar_choose, this);
		iv_1 = (ImageView) findViewById(R.id.level1);
		iv_2 = (ImageView) findViewById(R.id.level2);
		iv_3 = (ImageView) findViewById(R.id.level3);
		iv_4 = (ImageView) findViewById(R.id.level4);
		iv_5 = (ImageView) findViewById(R.id.level5);
	}

	private void clearStars() {
		iv_1.setImageResource(R.mipmap.def_star_normal);
		iv_2.setImageResource(R.mipmap.def_star_normal);
		iv_3.setImageResource(R.mipmap.def_star_normal);
		iv_4.setImageResource(R.mipmap.def_star_normal);
		iv_5.setImageResource(R.mipmap.def_star_normal);
	}

	public void show(int level) {
		clearStars();
		switch (level) {
		case 1:
			iv_1.setImageResource(R.mipmap.def_star_seltcted);
			break;

		case 2:
			iv_1.setImageResource(R.mipmap.def_star_seltcted);
			iv_2.setImageResource(R.mipmap.def_star_seltcted);
			break;
		case 3:
			iv_1.setImageResource(R.mipmap.def_star_seltcted);
			iv_2.setImageResource(R.mipmap.def_star_seltcted);
			iv_3.setImageResource(R.mipmap.def_star_seltcted);
			break;
		case 4:
			iv_1.setImageResource(R.mipmap.def_star_seltcted);
			iv_2.setImageResource(R.mipmap.def_star_seltcted);
			iv_3.setImageResource(R.mipmap.def_star_seltcted);
			iv_4.setImageResource(R.mipmap.def_star_seltcted);
			break;
		case 5:
			iv_1.setImageResource(R.mipmap.def_star_seltcted);
			iv_2.setImageResource(R.mipmap.def_star_seltcted);
			iv_3.setImageResource(R.mipmap.def_star_seltcted);
			iv_4.setImageResource(R.mipmap.def_star_seltcted);
			iv_5.setImageResource(R.mipmap.def_star_seltcted);
			break;
		}

	}

}
